//
//  AZLightWeightTextHUD.m
//  mobile
//
//  Created by abc on 2018/12/3.
//  Copyright © 2018 azazie. All rights reserved.
//

#import "AZLightWeightTextHUD.h"
#import <QMUIKit/QMUIKit.h>
#import <Masonry/Masonry.h>

@interface AZLightWeightTextHUD ()
@property (nonatomic, strong) UILabel *textLabel;
@end

@implementation AZLightWeightTextHUD

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self configureSubview];
    }
    return self;
}

- (instancetype)init {
    if (self = [super init]) {
        [self configureSubview];
    }
    return self;
}

- (void)configureSubview {
    UIView *maskView = [[UIView alloc] init];
    maskView.layer.cornerRadius = 3.f;
    maskView.layer.masksToBounds = YES;
    maskView.backgroundColor = UIColorBlack;
    maskView.alpha = 0.7f;
    
    self.textLabel = [[UILabel alloc] init];;
    self.textLabel.font = UIFontMake(13.f);
    self.textLabel.textColor = UIColorWhite;
    self.textLabel.textAlignment = NSTextAlignmentCenter;
    
    
    [self addSubview:maskView];
    [maskView addSubview:self.textLabel];
    [maskView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.height.equalTo(self);
    }];
    [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10.f);
        make.right.mas_equalTo(-10.f);
        make.center.equalTo(maskView);
    }];
}

- (void)hideAfterDelay:(NSTimeInterval)delay {
    [self performSelector:@selector(hideFromSuperView) withObject:nil afterDelay:delay];
}

- (void)hideFromSuperView {
    [UIView animateWithDuration:.3f animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.textLabel.text = title;
}

@end
